/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import StandardModule from '@/components/hyperspace/modules/StandardModule';
import ResetPsdForm from './components/ResetPsdForm';


let resetPsdForm: any = {};

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ userManage, dispatch }) => (
  <div>
    <StandardModule
      data={userManage.data}
      dictionary={[]}
      config={{
        common: {
          formItemOptions: {
            alias: {
              rules: [{ required: true, message: '昵称不能为空！' }],
            },
            loginId: {
              rules: [{ required: true, message: '登录密码不能为空！' }],
            },
            login_pwd: {
              rules: [{ required: true, message: '登录密码不能为空！' }],
            },
            confirmPassword: {
              rules: [{ required: true, message: '确认密码不能为空！' }],
            },
            mobile: {
              rules: [{ required: true, message: '手机号码不能为空！' }],
            },
            email: {
              rules: [{ required: true, message: '邮箱不能为空！' }],
            },
            roleIds: {
              rules: [{ required: true, message: '角色不能为空！' }],
            },

          },
        },
        search: {
          fields: ['alias', 'loginId', 'mobile'], // 查询条件
        },
        list: {
          url: MGMT_PATH + '/user/queryUserForPage',
          fields: [
            'id',
            'alias',
            'loginId',
            'mobile',
            'email',
            'creatTime',
          ], // 列表字段
          format: {
            username: {
              render: (value: any) => `格式化 - ${value}`,
            },
          },
          extensions: {
            operations: [
              (record: any) => (
                <span>
                  <a
                    onClick={() => {
                      if (resetPsdForm) resetPsdForm.handleOpen();
                    }}
                  >
                    重置密码
                  </a>
                </span>
              ),
            ],
          },
        },
        add: {
          url: MGMT_PATH + '/user/createUser',
          // width: 680, // 非必填，默认680px
          // title: '新建表单', // 非必填，默认`新建`
          fields: [
            'alias',
            'loginId',
            'login_pwd',
            'confirmLoginPwd',
            'mobile',
            'email',
            'roleIds',
          ], // 新增表单字段
        },
        update: {
          url: MGMT_PATH + '/user/updateUser',
          // width: 680, // 非必填，默认680px
          // title: '新建表单', // 非必填，默认`新建`
          fields: [
            'alias',
            'loginId',
            'mobile',
            'email',
            'roleIds',
          ], // 修改表单字段
          primaryKeys: ['id'], // 主键字段列表
        },
        delete: {
          url: MGMT_PATH + '/user/deleteUser',
          batchDelete: false, // 是否开启批量删除
          fields: ['id'], // 删除依据字段
        },
      }}
      namespace="userManage"
      dispatch={dispatch}
    />


    {/* eslint-disable-next-line no-return-assign */}
    <ResetPsdForm wrappedComponentRef={(inst: any) => (resetPsdForm = inst)}
      {...resetPsdForm}
      visible
    />
  </div>
);


// @ts-ignore
export default connect(({ userManage }) => ({
  userManage,
}))(LocalModule);
